import { _decorator, AudioClip, AudioSource, Component } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('$planet_AudioManager_poof$')
export class $planet_AudioManager_poof$ extends Component {
	private static $planet__ins_poof$: $planet_AudioManager_poof$;
	/** 全局唯一安全实例 */
	public static get $planet_ins_poof$(){
		return $planet_AudioManager_poof$.$planet__ins_poof$;
	}

	/** 音效类型 */
	public static get $planet_EFFECT_poof$(){
		return $planet_AudioEffect_poof$;
	}

	@property(AudioSource)
	private $planet_bgm_poof$: AudioSource = null;
	@property(AudioSource)
	private $planet_effect_poof$: AudioSource = null;
	@property([AudioClip])
	private $planet_clip_list_poof$: AudioClip[] = [];

	private $planet_clip_map_poof$ = new Map<string, AudioClip>();

	onLoad(){
		$planet_AudioManager_poof$.$planet__ins_poof$ = this;
		this.$planet_init_poof$();
	}

	private $planet_init_poof$(){
		this.$planet_clip_list_poof$.forEach(clip=>this.$planet_clip_map_poof$.set(clip.name, clip));
	}

	public $planet_playBGM_poof$(){
		if(this.$planet_bgm_poof$.state == AudioSource.AudioState.PLAYING) return void 0;

		if(!this.$planet_bgm_poof$.clip){
			this.$planet_bgm_poof$.clip = this.$planet_clip_map_poof$.get('bgm');
			this.$planet_bgm_poof$.loop = true;
		}

		this.$planet_bgm_poof$.play();
	}

	public $planet_pauseBgm_poof$(){
		if(this.$planet_bgm_poof$.state != AudioSource.AudioState.PLAYING) return void 0;
		this.$planet_bgm_poof$.pause();
	}

	public $planet_playEffect_poof$(effect: $planet_AudioEffect_poof$){
		let clip = this.$planet_clip_map_poof$.get(effect);
		if(!clip) return void 0;
		this.$planet_effect_poof$.playOneShot(clip);
	}
}

enum $planet_AudioEffect_poof$ {
	$planet_CLICK_poof$ = "click",
	$planet_AMAZING_poof$ = "Amazing",
	$planet_BGM_poof$ = "bgm",
	$planet_EXCELLENT_poof$ = "Excellent",
	$planet_FRUIT_poof$ = "fruit",
	$planet_GOOD_poof$ = "good",
	$planet_GREAT_poof$ = "great",
	$planet_PLANET_poof$ = "planet",
	$planet_SYNTHETIC_poof$ = "synthetic",
	$planet_UNBELIEVABLE_poof$ = "Unbelievable",
}
